@extends('admin.layout.app')

@section('title', '新增權限')
@section('menu', broute('permission.index'))

@section('style')
    <style>
        .layui-diy-title {
            position: relative;
            height: 42px;
            line-height: 42px;
            padding: 0 15px 0 16px;
            color: #333;
            background-color: #f2f2f2;
            cursor: pointer;
            font-size: 14px;
            overflow: hidden;
        }
        .layui-table td .layui-unselect {
            min-width: 200px;
        }
    </style>
@endsection
@section('content')
    <div class="layui-col-lg12">
        <div class="layui-card">
            <div class="layui-card-header">
                新增權限
            </div>
            <div class="layui-card-body">
                <form class="layui-form" action="@broute('permission.store')" method="POST">
                    <div class="layui-form-item">
                        <label class="layui-form-label">名稱</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required value="" autocomplete="off"
                                   class="layui-input permission_name">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">權限</label>
                        <div class="layui-input-block">
                            <table class="layui-table" lay-skin="line">
                                <colgroup>
                                    <col width="150">
                                    <col>
                                    <col width="150">
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>操作对象</th>
                                    <th>权限</th>
                                    <th>全选</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($format_routes as $key=>$route)
                                <tr>
                                    <td>
                                        {{$key}}
                                    </td>
                                    <td>
                                        @foreach($route as $k=>$v)
                                            <input type="checkbox" data-id="{{$v['name']}}" name="permissions[]"
                                                   lay-skin="primary" value="{{$v['name']}}"
                                                   title="{{$v['description']}}">
                                        @endforeach
                                    </td>
                                    <td>
                                        <input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose">
                                    </td>
                                </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function () {
            //全选
            form.on('checkbox(allChoose)', function (data) {
                var child = $(data.elem).parent().prev().find('input');
                child.each(function (index, item) {
                    item.checked = data.elem.checked;
                });
                form.render('checkbox');
            });
        });
    </script>
@endsection

